#!/usr/bin/env bash
# yitong.bai@qq.com
# Library for templating configurations functions

function TemplateKubesprayClusterEnvironment() {

  local http_repo="$1"
  local centos_base_repo_url="$2"
  local centos_extra_repo_url="$3"
  local docker_rh_repo="$4"
  local kube_image_repo="$5"
  local docker_image_repo="$6"
  local quay_image_repo="$7"
  local src_file="$8"
  local dst_file="$9"

  export http_repo
  export centos_base_repo_url
  export centos_extra_repo_url
  export docker_rh_repo
  export kube_image_repo
  export docker_image_repo
  export quay_image_repo
  export offline_server_docker_data_root

  envsubst < "${src_file}" > "${dst_file}"

  export -n http_repo
  export -n centos_base_repo_url
  export -n centos_extra_repo_url
  export -n docker_rh_repo
  export -n kube_image_repo
  export -n docker_image_repo
  export -n quay_image_repo
  export -n offline_server_docker_data_root
}

function TemplateKubesprayClusterInventory() {
  local srcFile="${1}"
  local dstFile="${2}"
  /bin/cp "${srcFile}" "${dstFile}"
}

# 暂时使用kubespray默认的download environment
#function TemplateKubesprayDownloadEnvironment() {}

# 设置下载机器本身的ansible inventory file
function TemplateKubesprayDownloadInventory() {
  local srcFile="${1}"
  local dstFile="${2}"
  export hostName="${3}"
  export ipAddress="${4}"

  envsubst < "${srcFile}" > "${dstFile}"

  export -n hostName
  export -n ipAddress
}

